/***********************************************************
 *
 * Gaoth
 * Copyright (c) 2011- Marcus Lundgren
 * 
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from
 * the use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it freely,
 * subject to the following restrictions:
 *
 *  1. The origin of this software must not be misrepresented; you must not
 *     claim that you wrote the original software. If you use this software
 *     in a product, an acknowledgment in the product documentation would be
 *     appreciated but is not required.
 *
 *  2. Altered source versions must be plainly marked as such,
 *     and must not be misrepresented as being the original software.
 *
 *  3. This notice may not be removed or altered from any source distribution.
 *
 ***********************************************************/

#pragma once

#include <SFML/Network.hpp>
#include <vector>

#include "client.h"

#include "entities/npc_entity.h"
#include "entities/pc_entity.h"

typedef std::vector<Client*> ClientVector;

/**
 * Holds information about the current game state and the connected clients.
 */
class Model
{
public:
    /**
     * Constructor.
     */
    Model();
    /**
     * Destructor.
     */
    ~Model();
    /**
     * Acquire the lock.
     */
    void acquire();
    /**
     * Release the lock.
     */
    void release();

    const ClientVector& get_clients() const;
    /**
     * Adds a client to the model.
     *
     * @param client the client to add.
     */
    void add_client( Client *client );
    /**
     * Removes a client from the model.
     *
     * @param id the id of the client.
     */
    void remove_client( const int id  );
    void remove_client( const sf::TcpSocket& socket );

    const std::vector<NPCEntity>& get_npc_entities() const;

    /**
     * Update the model.
     *
     * @param time milliseconds since last update.
     */
    void update( const float time );
    
private:
    /**
     * The connected clients.
     */
    ClientVector _clients;
    sf::Mutex _lock;

    std::vector<NPCEntity> _entities;

    // Illegal
    Model( const Model& );
    Model& operator=( const Model& );
};
